
UTILSRC= utils/src
UTILO = utils/obj
UTILINC = utils/inc
EXE = bin/crawler
TEST = bin/TestDriver

clean :
	@- rm -f bin/*
	@- rm -f obj/*.o 
	@- rm -f lib/*.a 
	@- rm -f $(UTILO)/*.o 

run: $(EXE)
	$(EXE) file:///users/ta/cs240ta/webcrawler/file/student/index.html XMLFile.txt stopword.txt
	
test: $(TEST) 
	$(TEST)
	
bin: $(EXE)

val:$(EXE)
	valgrind --tool=memcheck --leak-check=yes --max-stackframe=5000000 --show-reachable=yes --suppressions=string.supp $(EXE) http://students.cs.byu.edu/~cs240ta/crawler_tests/crawlindex.html XMLFile.txt stopword.txt
lib: lib/libc240utils.a

$(TEST) : Testing/TestDriver.cpp lib/libc240utils.a obj/Page.o
	g++ -o bin/TestDriver Testing/TestDriver.cpp

$(EXE) : obj/Crawler.o lib/libc240utils.a
	g++ -g -o $(EXE) -I inc/ -I utils/inc obj/*.o lib/libc240utils.a
	chmod a+x $(EXE)


obj/Crawler.o : src/Crawler.cpp obj/HTMLParser.o obj/KeyWordIndex.o obj/Occurrence.o obj/OccurrenceSet.o obj/PageHistory.o obj/StopWordList.o obj/URL.o obj/URLDownloader.o obj/URLHistory.o obj/URLQueue.o obj/URLValidator.o obj/XMLGenerator.o
	g++ -o obj/Crawler.o -c -I inc/ -I utils/inc src/Crawler.cpp
	
lib/libc240utils.a : $(UTILO)/CommandRunner.o  $(UTILO)/FileInputStream.o  $(UTILO)/FileSystem.o  $(UTILO)/HTTPInputStream.o  $(UTILO)/StringUtil.o $(UTILO)/HTMLTokenizer.o $(UTILO)/HTMLToken.o $(UTILO)/URLInputStream.o
	ar r lib/libc240utils.a $(UTILO)/*.o

$(UTILO)/CommandRunner.o: $(UTILSRC)/CommandRunner.cpp $(UTILINC)/CommandRunner.h $(UTILINC)/CS240Exception.h $(UTILINC)/StringUtil.h
	g++ -g -o $(UTILO)/CommandRunner.o -c -I $(UTILINC) $(UTILSRC)/CommandRunner.cpp

$(UTILO)/FileInputStream.o: $(UTILSRC)/FileInputStream.cpp $(UTILINC)/FileInputStream.h $(UTILINC)/InputStream.h $(UTILINC)/CS240Exception.h
	g++ -g -o $(UTILO)/FileInputStream.o -c -I $(UTILINC) $(UTILSRC)/FileInputStream.cpp

$(UTILO)/FileSystem.o: $(UTILSRC)/FileSystem.cpp $(UTILINC)/FileSystem.h $(UTILINC)/CS240Exception.h $(UTILINC)/UnitTest.h
	g++ -g -o $(UTILO)/FileSystem.o -c -I $(UTILINC) $(UTILSRC)/FileSystem.cpp

$(UTILO)/HTTPInputStream.o: $(UTILSRC)/HTTPInputStream.cpp $(UTILINC)/HTTPInputStream.h $(UTILINC)/InputStream.h $(UTILINC)/CS240Exception.h
	g++ -g -o $(UTILO)/HTTPInputStream.o -c -I $(UTILINC) $(UTILSRC)/HTTPInputStream.cpp

$(UTILO)/StringUtil.o: $(UTILSRC)/StringUtil.cpp $(UTILINC)/StringUtil.h
	g++ -g -o $(UTILO)/StringUtil.o -c -I $(UTILINC) $(UTILSRC)/StringUtil.cpp

$(UTILO)/HTMLTokenizer.o: $(UTILSRC)/HTMLTokenizer.cpp $(UTILINC)/HTMLTokenizer.h
	g++ -g -o $(UTILO)/HTMLTokenizer.o -c -I $(UTILINC) $(UTILSRC)/HTMLTokenizer.cpp

$(UTILO)/HTMLToken.o: $(UTILSRC)/HTMLToken.cpp $(UTILINC)/HTMLToken.h
	g++ -g -o $(UTILO)/HTMLToken.o -c -I $(UTILINC) $(UTILSRC)/HTMLToken.cpp

$(UTILO)/URLInputStream.o: $(UTILSRC)/URLInputStream.cpp $(UTILINC)/StringUtil.h $(UTILINC)/CS240Exception.h $(UTILINC)/HTTPInputStream.h $(UTILINC)/FileInputStream.h $(UTILINC)/URLInputStream.h $(UTILINC)/InputStream.h
	g++ -g -o $(UTILO)/URLInputStream.o -c -I $(UTILINC) $(UTILSRC)/URLInputStream.cpp
	
obj/HTMLParser.o: src/HTMLParser.cpp inc/HTMLParser.h obj/URL.o inc/LinkedList.h lib/libc240utils.a
	g++ -g -o obj/HTMLParser.o -c -I inc/ -I utils/inc/ src/HTMLParser.cpp

obj/KeyWordIndex.o: src/KeyWordIndex.cpp inc/KeyWordIndex.h inc/BST.h inc/LinkedList.h obj/OccurrenceSet.o
	g++ -g -o obj/KeyWordIndex.o -c -I inc/ src/KeyWordIndex.cpp

obj/OccurrenceSet.o: src/OccurrenceSet.cpp inc/OccurrenceSet.h obj/Occurrence.o inc/BST.h inc/LinkedList.h
	g++ -g -o obj/OccurrenceSet.o -c -I inc/ src/OccurrenceSet.cpp	
	
obj/Occurrence.o: src/Occurrence.cpp inc/Occurrence.h obj/Page.o
	g++ -g -o obj/Occurrence.o -c -I inc/ src/Occurrence.cpp	
	
obj/Page.o: src/Page.cpp inc/Page.h inc/LinkedList.h obj/URL.o
	g++ -g -o obj/Page.o -c -I inc/ src/Page.cpp	
	
obj/PageHistory.o:src/PageHistory.cpp inc/PageHistory.h inc/BST.h obj/URL.o obj/Page.o
	g++ -g -o obj/PageHistory.o -c -I inc/ src/PageHistory.cpp	
	
obj/StopWordList.o: src/StopWordList.cpp inc/StopWordList.h
	g++ -g -o obj/StopWordList.o -c -I /inc src/StopWordList.cpp
	
obj/URL.o: src/URL.cpp inc/URL.h
	g++ -g -o obj/URL.o -c -I inc/ src/URL.cpp
	
obj/URLDownloader.o: src/URLDownloader.cpp  inc/URLDownloader.h obj/URL.o lib/libc240utils.a
	g++ -g -o obj/URLDownloader.o -c -I inc/ -I utils/inc/ src/URLDownloader.cpp
		
obj/URLHistory.o: src/URLHistory.cpp  inc/URLHistory.h obj/URL.o obj/Page.o inc/BST.h
	g++ -g -o obj/URLHistory.o -c -I inc/ src/URLHistory.cpp

obj/URLQueue.o: src/URLQueue.cpp  inc/URLQueue.h obj/URL.o inc/LinkedList.h 
	g++ -g -o obj/URLQueue.o -c -I inc/ src/URLQueue.cpp

obj/URLValidator.o: src/URLValidator.cpp  inc/URLValidator.h obj/URL.o obj/urlResolver.o lib/libc240utils.a
	g++ -g -o obj/URLValidator.o -c -I inc/ -I utils/inc/ src/URLValidator.cpp

obj/urlResolver.o: src/urlResolver.cpp  inc/urlResolver.h
	g++ -g -o obj/urlResolver.o -c -I inc/ src/urlResolver.cpp

obj/XMLGenerator.o:src/XMLGenerator.cpp inc/XMLGenerator.h inc/LinkedList.h obj/Page.o obj/Occurrence.o	obj/KeyWordIndex.o obj/PageHistory.o lib/libc240utils.a
	g++ -g -o obj/XMLGenerator.o -c -I inc/ -I utils/inc/ src/XMLGenerator.cpp


